#include <stdio.h>
#include <stdlib.h>

typedef unsigned long long int ull;
#define SIZETAB 16
const int TAB[] = {0, 3, 5, 6, 4, 5, 6, 7, 8, 19, 23, 45, 67, 78, 89, 100, 140, 150, 160};

int getT(int * t, int k, int ta) {
	int sum = k, i;
	for(i = 1; i <= ta; i++) {
		sum += (ta / t[i]);
	}
	return sum;
}

int binFindUpT(int * t, int min, int max, int n, int k) {
	int d, mid, p;
	while(max >= min) {
		mid = (max + min) / 2;
		if(getT(t, k, mid) < n)
			min = mid + 1;
		else if(getT(t, k, mid) >= n) {
			if(getT(t, k, mid - 1) < n)
				return mid;
			max = mid - 1;
		}
	}
	return 0; //not found
}

int main() {
	int k, *t, i;
	ull n;
/*
	k = 67; i = binFindUpT(TAB, 0, SIZETAB-1, k);
	printf("TAB[%d]=%d > %d\n", i, TAB[i], k);

	k = 68; i = binFindUpT(TAB, 0, SIZETAB-1, k);
	printf("TAB[%d]=%d > %d\n", i, TAB[i], k);

	k = 161; i = binFindUpT(TAB, 0, SIZETAB-1, k);
	printf("TAB[%d]=%d > %d\n", i, TAB[i], k);

	k = 3; i = binFindUpT(TAB, 0, SIZETAB-1, k);
	printf("TAB[%d]=%d > %d\n", i, TAB[i], k);
*/
	
	i = binFindUpT(TAB, 1, 3, 10, 3);
	printf("i=%d\n", i);
	return 0;
	
	scanf("%llu %d", &n, &k);
	t = malloc((k + 1) * sizeof(int));
	
	for(i = 1; i <= k; i++) {
		scanf("%d", &t[i]);
	}
	
	
	return 0;
}
